package com.itheima;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/findOneServlet")
public class FindOneServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求参数id
        String id = request.getParameter("id");
        int i = Integer.parseInt(id);
        //根据id查询一个对象
        UserDao dao=new UserDao();
        User user = dao.findOneUser(i);
        //把对象放在域中



        ServletContext context = request.getServletContext();
        context.setAttribute("user",user);



        request.setAttribute("user",user);
        //转发到update.jsp页面
        request.getRequestDispatcher("/update.jsp").forward(request,response);
    }
}
